package com.mmall.example.atomic;


import com.mmall.annoations.ThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.LongAdder;

/**
 * 线程安全的 --> AtomicReference
 * Created by megan on 2018/3/18.
 */
@Slf4j
@ThreadSafe
public class AtomicReferenceExample {
    private static AtomicReference<Integer> count = new AtomicReference<>(0);

    public static void main(String[] args) {
        // 2
        count.compareAndSet(0,2);
        // no
        count.compareAndSet(0,1);
        // no
        count.compareAndSet(1,3);
        // 4
        count.compareAndSet(2,4);
        // no
        count.compareAndSet(3,5);
        log.info("count:{}",count);
    }

}
